
# 删除字符串中不需要的字符，想去掉文本字符串开头，结尾或者中间不想要的字符，比如空白
def demo_1():
    s = ' hello kepler \n'
    print(s)
    print(s.strip())
    print(s.lstrip())
    print(s.rstrip())

    # 去掉字符串前后固定的目标字符
    t = '-----kepler===='
    print(t.lstrip('-'))
    print(t.rstrip('='))
    print(t.strip('-='))

# 去掉字符串内的空格
def demo_2():
    s = ' hello kepler \n'
    print(s.replace(' ', ''))

def handle(filename):
    with open(filename) as f:
        lines = (line.strip() for line in f)
        for line in lines:
            print(line)

# 批量处理文本每一行的前后空格
def demo_3():
    filename = '../temp/test1.txt'
    handle(filename)


if __name__ == '__main__':
    # demo_1()
    # demo_2()
    demo_3()